stages:
  - build
  - upload
  - deploy

build_backend:
  stage: build
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  script:
    - docker build -t backend:$CI_COMMIT_SHORT_SHA ./EXTimeProject

# build_frontend:
#   stage: build
#   rules:
#     - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
#   script:
#     - docker build -t frontend:$CI_COMMIT_SHORT_SHA ./extime

upload_backend:
  stage: upload
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  needs:
    - job: build_backend
  script:
    - kind load docker-image backend:${CI_COMMIT_SHORT_SHA}

# upload_frontend:
#   stage: upload
#   rules:
#     - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
#   needs:
#     - job: build_frontend
#   script:
#     - kind load docker-image frontend:${CI_COMMIT_SHORT_SHA}

deploy:
  stage: deploy
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  needs:
    - job: upload_backend
    # - job: upload_frontend
  environment:
    name: production
  script:
    # - kubectl create configmap myapp-conf --from-file=< etc или config>/ --namespace=default -o yaml --dry-run=client | kubectl apply -f -
    - kubectl set image deployment/django-deployment django-app=backend:${CI_COMMIT_SHORT_SHA}
    # - kubectl set image deployment/react-deployment react-app=frontend:${CI_COMMIT_SHORT_SHA}
    - kubectl get pods -o wide
